package com.hqs.drawingboard;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;

import java.io.File;

/**
 * Created by super on 2017/4/14.
 */

public class NotificationUtil {

    public static void show(Activity activity, String title, String filePath) {

        PackageManager packageManager = activity.getPackageManager();
        try {
            Notification.Builder builder = new Notification.Builder(activity);

            PackageInfo packageInfo = packageManager.getPackageInfo(
                    activity.getPackageName(), 0);
            int icon = packageInfo.applicationInfo.icon;

            builder.setSmallIcon(icon);
            builder.setContentTitle(title);

            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(new File(filePath)), "image/*");
            Notification notification = builder.build();
            PendingIntent contentIntent = PendingIntent.getActivity(activity, 0, intent, 0);
            notification.contentIntent = contentIntent;
            notification.flags = Notification.FLAG_AUTO_CANCEL;

            NotificationManager nm = (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE);
            nm.notify(6788, notification);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}


